package com.fernfx.xingtan.utils;


import com.fernfx.xingtan.common.base.BaseFragment;
import com.fernfx.xingtan.main.ui.ChatFragment;
import com.fernfx.xingtan.main.ui.ContactsInfoFragment;
import com.fernfx.xingtan.main.ui.MyFragment;
import com.fernfx.xingtan.user.AccountManager;

import java.util.HashMap;

public class FragmentFactoryUtil {
    /**
     * 首页
     */
    public static final int NAV_CHAT = 0;

    /**
     * 通讯录
     */
    public static final int NAV_HISTROY = 1;

    /**
     * 明星生活
     */
    public static final int NAV_CLAP_PICTURE = 2;

    /**
     * 我的
     */
    public static final int NAV_MY = 3;

    public static HashMap<Integer, BaseFragment> fragmentCache = new HashMap<>();

    public static BaseFragment createFragment(int position) {
        BaseFragment fragment = fragmentCache.get(position);
        if (fragment != null) {
            return fragment;
        }
        switch (position) {
            case NAV_CHAT:
                if (AccountManager.isLogin()) {
                    fragment = new ChatFragment();
                }
                break;
            case NAV_HISTROY:
                if (AccountManager.isLogin()) {
                    fragment = new ContactsInfoFragment();
                }
                break;
            case NAV_MY:
                if (AccountManager.isLogin()) {
                    fragment = new MyFragment();
                }
                break;
            default:
                break;
        }
        fragmentCache.put(position, fragment);
        return fragment;
    }

    public static void clear() {
        fragmentCache.clear();
    }
}
